//
//  StepViewController.m
//  Menu
//
//  Created by YouLu on 15/7/3.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "StepViewController.h"

@interface StepViewController ()

@end

@implementation StepViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.stepModelArray = [NSMutableArray array];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.frame = CGRectMake(0, 64+260*HEIGHT+40*HEIGHT, MyWidth, MyHeight-64-49-260*HEIGHT-40*HEIGHT);
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MyWidth, MyHeight-64-49-260*HEIGHT-40*HEIGHT) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle =UITableViewCellSeparatorStyleNone;
    self.tableView.bounces = YES;
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText = @"loading";
    [self.HUD show:YES];

}
-(void)loadData:(NSString *)vegetableId
{
    NSString *stepStrUrl = [NSString stringWithFormat:@"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=%@&type=2&phonetype=0&is_traditional=0",vegetableId];
    [AFNTool get:stepStrUrl Body:nil HttpResult:JSON success:^(id result) {
        
        NSMutableArray *dataArray = [result objectForKey:@"data"];
        for (NSMutableDictionary *dic in dataArray) {

            StepModel *model = [[StepModel alloc] initWithDic:dic];
            [self.stepModelArray addObject:model];

        }
        [self.tableView reloadData];
        [self.HUD hide:YES];
    } failure:^(NSError *error) {
        
        self.HUD.labelText = @"加载失败";
        [self.HUD hide:YES afterDelay:1];
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.stepModelArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    StepTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[StepTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = [self.stepModelArray objectAtIndex:indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 250*HEIGHT;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
